package de.slothsoft.commons.swing;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Window;

public abstract class WindowUtil {

    public static void centerWindow(Window window) {
	Toolkit tk = Toolkit.getDefaultToolkit();
	Dimension size = tk.getScreenSize();
	centerWindowOnRectangle(window, size.width, size.height);
    }

    public static void centerWindowOnRectangle(Window window, int width, int height) {
	centerWindowOnRectangle(window, width, height, 0, 0);
    }

    public static void centerWindowOnRectangle(Window window, int width, int height, int offsetX, int offsetY) {
	Dimension windowSize = window.getSize();
	int windowHeight = windowSize.height;
	int windowWidth = windowSize.width;

	int x = offsetX + (width - windowWidth) / 2;
	int y = offsetY + (height - windowHeight) / 2;

	window.setLocation(x, y);
    }

    private WindowUtil() {
	// hide
    }
}
